
#include <Windows.h>
#include "Application.h"
#include "Core/Log/LogManager.h"
#include "../Layout/VerticalLayout.h"
#include "../Layout/HorizontalLayout.h"
#include "../Button/Button.h"
#include "../Impl/Application/WindowImpl.h"
#include "Window.h"

namespace GUI
{
	namespace Win32
	{
		Window::Window() : m_pImpl(NULL)
		{
		}

		Window::~Window()
		{
			if (m_pImpl)
			{
				delete m_pImpl;
			}
		}

		bool Window::Create(const std::string & _strTitle, uint32 _iWidth, uint32 _iHeight)
		{
			m_pImpl = new WindowImpl(_strTitle, _iWidth, _iHeight);
			if (!m_pImpl->Create(this))
			{
				delete m_pImpl;
				m_pImpl = NULL;
				return false;
			}

			ShowWindow(m_pImpl->GetHandle(), SW_SHOWDEFAULT); // genere un evenement WM_SIZE
			UpdateWindow(m_pImpl->GetHandle());

			return true;
		}

		const std::string & Window::GetTitle()
		{
			return m_pImpl->GetTitle();
		}

		void Window::Loop()
		{
			MSG msg = { 0 };
			while (WM_QUIT != msg.message)
			{
				if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
				{
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}
			}
		}

		void Window::OnResize(VoidFunctionIntInt _onResizeFunc)
		{

		}

		Core::GUI::WidgetType Window::GetType() const
		{
			return Core::GUI::Window;
		}

		int Window::GetId() const
		{
			return m_pImpl->GetId();
		}

		int Window::GetWidth() const
		{
			return m_pImpl->GetWidth();
		}

		int Window::GetHeight() const
		{
			return m_pImpl->GetHeight();
		}

		int Window::GetX() const
		{
			return m_pImpl->GetX();
		}

		int Window::GetY() const
		{
			return m_pImpl->GetY();
		}

		void Window::SetSize(int _iWidth, int _iHeight)
		{
			m_pImpl->SetSize(_iWidth, _iHeight);
		}

		void Window::SetPosition(int _x, int _y)
		{
			m_pImpl->SetPosition(_x, _y);
		}

		/*void Window::SetBackgroundColor(uchar _iRed, uchar _iGreen, uchar _iBlue)
		{
			PAINTSTRUCT ps;
			RECT rc;
			HDC hdc = BeginPaint(m_hWnd, &ps);
			GetClientRect(m_hWnd, &rc);
			SetBkColor(hdc, 0x000000ff);
			EndPaint(m_hWnd, &ps);
		}*/
	}
}